# -*- coding: utf-8 -*-
"""
Created on Wed Apr 29 13:36:30 2020

@author: Farman
"""


import pathlib
import MatlabMatMan
import joblib
import sys


def tran(mat_file):
    '''
    Translate Matlab .mat data file to MyPersistence data file.

    Parameters
    ----------
    mat_file : string.
        Matlab .mat data file name.

    Returns
    -------
    MyPersistence data file name after translation.
    '''
    if mat_file[-4:] == '.mat':
        per_file = mat_file[:-4]
    
    per_file += '.joblib'
    joblib.dump(MatlabMatMan.mat2array(mat_file), per_file)
    return per_file


if __name__ =='__main__':
    print('-' * 20)
    print(' ' * 5, 'Matlab .mat -> MyPersistence persistence file.')
    print('-' * 20)
    
    if len(sys.argv) == 1:
        ans = input('Matlab .mat file :')
        
        if len(ans):
            tran(ans)
        else:
            print('Usage:')
            print('python3 Matlab2MyPer.py')
            print('or')
            print('python3 Matlab2MyPer.py matlab_mat_file')
    elif len(sys.argv) == 2:
        ans = sys.argv[1]
        tran(ans)
    else:
        print('Usage:')
        print('python3 Matlab2MyPer.py')
        print('or')
        print('python3 Matlab2MyPer.py matlab_mat_file')